//
//  CommentCell.swift
//  BaseSwift
//
//  Created by gh on 2019/10/11.
//  Copyright © 2019 ghwang. All rights reserved.
//

import UIKit

class CommentCell: UITableViewCell {

    let containerView = UIView()
    let nickLab = UILabel()
    let timeLab = UILabel()
    let contLab = UILabel()
    let icon = UIImageView()

    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.selectionStyle = .none
        contentView.addSubview(containerView)
        containerView.backgroundColor = UIColor.white
        let _ = containerView.sd_layout()?.spaceToSuperView(.zero)
        
        let bg = UIView()
        containerView.addSubview(bg)
        let _ = bg.sd_layout()?.widthRatioToView(containerView,1)!.heightIs(50)!.topSpaceToView(containerView,0)
        
        bg.addSubview(icon)
        let _ = icon.sd_layout()?.widthIs(32)!.heightIs(32)!.leftSpaceToView(bg,16)!.centerYEqualToView(bg)
        icon.sd_cornerRadius = 16
        

        bg.addSubview(nickLab)
        nickLab.textColor = UIColor.textTitleColorBlack
        nickLab.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight(rawValue: 0.2))
        nickLab.text = "核桃酥"
        let _ = nickLab.sd_layout()?.leftSpaceToView(icon,16)!.heightIs(20)!.topSpaceToView(bg,5)!.rightSpaceToView(bg,45)
        
        bg.addSubview(timeLab)
        timeLab.textColor = UIColor.textPlaceHolderColor
        timeLab.font = UIFont.smallerFont
        timeLab.text = "2019-09-09"
        let _ = timeLab.sd_layout()?.leftSpaceToView(icon,16)!.heightIs(15)!.topSpaceToView(nickLab,2)!.rightSpaceToView(bg,45)
        
        
        containerView.addSubview(contLab)
        contLab.textColor = UIColor.tabbarDefaultTextColor
        contLab.font = UIFont.commonFontSmaller
        contLab.text = "这里是我发表的评论，可以删除，照过可以通过左滑查看更多；评论内容超过三行的话，就折叠起来…"
        let _ = contLab.sd_layout()?.leftSpaceToView(containerView,64)?.topSpaceToView(bg,16)?.autoHeightRatio(0)?.rightSpaceToView(containerView,16)
        contLab.setMaxNumberOfLinesToShow(999)
    }

    func setModel(mod:CommentVo){
        
        
        if mod.userName?.phoneValidate == true {
            
            nickLab.text = mod.userName!.mobileSecure(mobile: mod.userName!)

        }else{
            
            nickLab.text = mod.userName

        }
        
        contLab.text = mod.content
        timeLab.text = mod.createTime?.split(string: "T")[0]
        icon.sd_setImage(with: URL(string:mod.userHead ?? ""), placeholderImage: UIImage(named: "默认头像"), options: .lowPriority) { (A, B, C, D) in
            
        }
        
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
